package cn.itcast.itcaststore.domain;

/**
 * 商品表
 */
public class Products {
    private static final long serialVersionUID = 1L;
    //商品id
    private String id;
    //商品名
    private String name;
    //商品价格
    private double price;
    //商品分类
    private String category;
    //商品库存
    private int pNum;
    //商品图片地址
    private String imgUrl;
    //商品描述
    private String description;

    public Products() {
    }

    public Products(String id, String name, double price, String category, int pNum, String imgUrl, String description) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.category = category;
        this.pNum = pNum;
        this.imgUrl = imgUrl;
        this.description = description;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public int getpNum() {
        return pNum;
    }

    public void setpNum(int pNum) {
        this.pNum = pNum;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    // a.jpg a_s.jpg
    public String getImgurl_s() {
        int index = imgUrl.lastIndexOf("."); // 得到最的.的索引
        String first = imgUrl.substring(0, index);

        String last = imgUrl.substring(index);

        return first + "_s" + last;
    }

    public void setImgUrl(String imgUrl) {
        this.imgUrl = imgUrl;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Products other = (Products) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "Products{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", price=" + price +
                ", category='" + category + '\'' +
                ", pNum=" + pNum +
                ", imgUrl='" + imgUrl + '\'' +
                ", description='" + description + '\'' +
                '}';
    }
}
